import { createStore, Store, useStore } from 'vuex';
import type { IRootState, IRootStore } from './type';

import LoginModule from './login/login';

const store = createStore<IRootState>({
  state: () => {
    return {
      name: 'xiaoming',
      number: 1,
      // friend: [1, 2, 3],
    };
  },
  mutations: {
    // eslint-disable-next-line
    get(state) {
      // state.friend = [11];
    },
  },
  actions: {},
  getters: {},
  modules: {
    LoginModule,
  },
});

export default store;

// 页面初始化时  将本地 token、个人信息、菜单 存储到vuex
export function setupStore() {
  store.dispatch('LoginModule/initLocalLogin');
}

// 覆盖 useStore 因为 useStore 内没有模块类型约束
export function useVuex(): Store<IRootStore> {
  return useStore();
}
